//
//  TWFXPM25Info.m
//  TWFXWeather
//
//  Created by Lion User on 13-10-3.
//  Copyright (c) 2013年 Lion User. All rights reserved.
//

#import "TWFXStruct_AQIInfo.h"

@implementation TWFXStruct_AQIInfo

-(id)init
{
    if (self = [super init]) {
        
        
    }
    
    return  self;
}

////"aqi":319,"area":"哈尔滨","position_name":null,"primary_pollutant":null,"quality":"严重污染","station_code":null,"time_point":"2013-10-19T14:00:00Z"

-(void)dealloc
{
    self.aqi = nil;
    self.quality = nil;
    self.time_point = nil;
    self.area = nil;
    
    [super dealloc];
}


+(void)AQIInfoWithDictionary:(NSDictionary *)dicData AQIInfo:(TWFXStruct_AQIInfo *)aqiInfo Error:(NSError *)error
{
    if (dicData == nil) {
        
        return;
    }
    
    if (aqiInfo == nil) {
        
        aqiInfo = [[TWFXStruct_AQIInfo alloc] init];        
    }
    
    @try {
        
        aqiInfo.aqi = dicData[@"aqi"];
        aqiInfo.area = dicData[@"area"];
        aqiInfo.quality = dicData[@"quality"];
        aqiInfo.time_point = dicData[@"time_point"];
//        
//        int aqi = [aqiInfo.AQI intValue];
//        
//        if (aqi < 50)
//        {
//            aqiInfo.quality = @"优";
//        }
//        else if(aqi < 100 && aqi >= 50)
//        {
//            aqiInfo.quality = @"良";             
//        }
//        else if(aqi < 200 && aqi >= 100)
//        {            
//            aqiInfo.quality = @"轻度污染"; 
//        }
//        else if(aqi < 300 && aqi >= 200)
//        {            
//            aqiInfo.quality = @"中度污染"; 
//        }
//        else if(aqi >= 300)
//        {            
//            aqiInfo.quality = @"中度污染";
//        }
    }
    @catch (NSException *exception) {
        
        error = [NSError errorWithDomain:exception.name code:0 userInfo:[exception userInfo]];

    }
    @finally {
        
    }
    

}


- (id) initWithCoder: (NSCoder *)coder
{
    if (self = [super init])
    {
        self.aqi = [coder decodeObjectForKey:@"aqi"];
        self.area = [coder decodeObjectForKey:@"area"];
        self.quality = [coder decodeObjectForKey:@"quality"];
        self.time_point = [coder decodeObjectForKey:@"time_point"];
        
    }
    
    return self;
}


- (void) encodeWithCoder: (NSCoder *)coder
{
    [coder encodeObject:self.aqi forKey: @"aqi"];
    [coder encodeObject:self.area forKey: @"area"];
    [coder encodeObject:self.quality forKey:@"quality"];
    [coder encodeObject:self.time_point forKey:@"time_point"];
}


@end
